package org.gavin.core.conf;

import lombok.extern.slf4j.Slf4j;
import org.gavin.core.service.safety.SafetyAbstract;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

/**
 * DefaultSafetyCondition
 *
 * @author grl
 * @date 2024/1/17
 */
@Slf4j
public class DefaultSafetyCondition  implements Condition {

    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        Map<String, SafetyAbstract> beansOfType = beanFactory.getBeansOfType(SafetyAbstract.class);
        return beansOfType.isEmpty();
    }
}
